public <T> T findNeighbor(Class<T> c, String[] props, Object[] values, 
        String limitProp, Date limit, boolean isBefore) throws Exception{
	Session session = getLocalSession();
	Criteria cr = session.createCriteria(c);
	for(int i = 0; i<pnList.length; i++){
			cr.add(Restrictions.eq(props[i], values[i]));
	}
	if(isBefore){
		cr.add(Restrictions.le(limitProp, limit);
		cr.setProjection(Projections.max(limitProp);
	}else{
		cr.add(Restrictions.gt(limitProp, limit))
		cr.setProjection(Projections.min(limitProp));
	}
	Date last = cr.uniqueResult();
	cr = session.createCriteria(c);
	for(int i = 0; i<pnList.length; i++){
			cr.add(Restrictions.eq(props[i], values[i]));
	}
	cr.add(Restrictions.eq(limitProp, limit);
	List result = cr.list();
	if(result.size() == 0) return null;
	return result.get(0);
}

